/*
 * Modelo_0.cpp
 *
 *  Created on: 16/06/2013
 *      Author: pato
 */

#include "Modelo_0.h"

Modelo_0::Modelo_0():Modelo(0) {
	this->caracteresDelContexto = new list<Caracter*>;
	Caracter * eof = new Caracter(EoF);
	this->caracteresDelContexto->push_back(eof);      //Va a ser cambiado por el caracter de salida
	for (int i=0;i<256;i++) {
		Caracter * c = new Caracter( string( 1,i ) ); //Necesito que se inicien con el contador en 1
		this->caracteresDelContexto->push_back(c);
	}
}

Caracter* Modelo_0::buscarCaracter(Aritmetico* compresor,string contexto) {
	Caracter* caracter = NULL;
	caracter = compresor->descomprimir_caracter(this->caracteresDelContexto);
	return caracter;
}
int Modelo_0::AgregarCaracter(Caracter *caracter, string cadena) {
	return 0;
}

int Modelo_0::ComprimirCaracter(string cadena, Aritmetico *compresor) {
	//separar el ultimo
	Caracter* caracter = new Caracter(cadena.substr(cadena.size()-1, 1));
	compresor->comprimir(this->caracteresDelContexto, caracter);
	return 0;
}

int Modelo_0::TerminarCompresion(string cadena, Aritmetico *compresor) {
	Caracter* caracter = new Caracter(EoF);
	compresor->comprimir(this->caracteresDelContexto, caracter);
	return 0;
}


Modelo_0::~Modelo_0() {
	std::list<Caracter*>::const_iterator it;
	for (it = this->caracteresDelContexto->begin(); it != this->caracteresDelContexto->end(); ++it) {
		Caracter* caracter = *it;
		delete(caracter);
	}
	this->caracteresDelContexto->clear();
	delete this->caracteresDelContexto;
}
